package com.njtoyo.taxi.admin.mapper.secondary.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.library.Const;
import com.njtoyo.taxi.admin.mapper.secondary.entity.AdminUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njtoyo.taxi.admin.rest.presenter.platfrom.adminUser.AdminUserListPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.platform.adminUser.AdminUserListWrapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Dell
 * @since 2021-06-17
 */
@Repository
@DS(Const.SECONDARY_DS)
public interface AdminUserMapper extends BaseMapper<AdminUser> {

    Map selectByAccount(String account);

    @Select("SELECT user_id FROM user_role_mapping WHERE role_id = #{roleId}")
    List<Long> getAdminUserIdsByRoleId(@Param("roleId") Long roleId);

    @Select("SELECT user_role_mapping.user_id FROM resource " +
            "LEFT JOIN role_resource_mapping ON resource.id = role_resource_mapping.resource_id " +
            "LEFT JOIN user_role_mapping ON role_resource_mapping.role_id = user_role_mapping.role_id " +
            "WHERE resource.id = #{id}")
    List<Long> getAdminUserIdsByResourceId(Long id);

    Page<AdminUserListPresenter> selectByPage(AdminUserListWrapper adminUserListWrapper);

    @Select("SELECT id FROM admin_user WHERE is_phone_online = 1")
    List<Long> getPhoneOnlineAdminUserIds();

    @Select("select * from admin_user where account = #{account}")
    AdminUser getByAccount(String account);

    @Select("select * from admin_user where mobile_number = #{mobileNumber}")
    AdminUser getByMobileNumber(String mobileNumber);

    List<com.njtoyo.taxi.entity.backend.AdminUser> selectNameList(List<Integer> list);
}
